package io.zhifei.modules.sys.pr.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.*;
import io.zhifei.common.utils.PageUtils;
import io.zhifei.common.utils.Query;
import io.zhifei.common.utils.R;
import io.zhifei.modules.sys.pr.entity.Statement;
import io.zhifei.modules.sys.pr.service.StatementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 报表控制器
 *
 * @author qdp
 * @Date 2021-08-09 14:40:34
 */
@Controller
@RequestMapping("/statement")
@Api(value = "报表控制器",description = ("报表控制器"))
public class StatementController {

    @Autowired
    private StatementService statementService;

    /**
     * 查看报表列表
     *
     * @author qdp
     * @Date 2021-08-09
     */
    @ResponseBody
    @GetMapping("/list")
    @ApiOperation("查看报表列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", paramType = "query", required = true),
            @ApiImplicitParam(name = "limit", value = "当前页大小", paramType = "query", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "请求成功", response = Statement.class)
    })
    public R list(@RequestParam Map<String, Object> pageParam) {
        return R.ok().put("page", new PageUtils(this.statementService.page(new Query<Statement>().getPage(pageParam), new QueryWrapper<>())));
    }


    /**
     * 新增或者更新调度报表接口
     *
     * @author qdp
     * @date 2021-08-09
     */
    @PostMapping("/submit")
    @ApiOperation(value = "新增或者更新报表接口", notes = "新增接口")
    @ResponseBody
    public R addSchedu(@RequestBody Statement statement) {
        if(this.statementService.saveOrUpdate(statement))return R.ok();
        else return R.error();
    }
}
